package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import service.ShiroService;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ShiroController {

    @Autowired
    private ShiroService shiroService;

    @RequestMapping("login.html")
    public String login(String userName, String password, Model model,HttpSession session) {
        try {
            shiroService.doLogin(userName, password);
            List<String> menus = shiroService.getUserMenu(userName);
            session.setAttribute("menus", menus);
            return "/index.jsp";
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute("message", e.getMessage());
            return "/login.jsp";
        }
    }
}
